package start.demo01.socket;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

public class ClientSocket1 {

    public static void main(String[] args) throws IOException {
        ClientSocket1 client=new ClientSocket1();
        //client.create();
        client.client();
    }
    public void create() throws IOException {
        String host = "127.0.0.1";
        int port = 8888;
        // 与服务端建立连接
        Socket socket = new Socket(host, port);
        // 建立连接后获得输出流
        OutputStream outputStream = socket.getOutputStream();
        String message="你好  这次链接成功了";
        socket.getOutputStream().write(message.getBytes("UTF-8"));
        outputStream.close();
        socket.close();

    }
    public void client() throws IOException {
        String host = "127.0.0.1";
        int port = 8888;
        Socket socket=new Socket(host,port);
        new Thread(new TalkTask(socket)).start();
    }
}
